<?php

namespace mpend\modules\team\controllers;

use Yii;
use mpend\components\Controller;
use mpend\modules\team\models\TeamBookDateStatsSearch;
use mpend\modules\team\models\MemberDashboardLogic;
use mpend\modules\team\models\BookMemberInviteForm;
use mpend\modules\team\models\BookMemberForm;

/**
 * 记工本详情管理
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class MemberController extends Controller {

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
            'update' => ['POST'],
            'invite' => ['POST'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actionIndex($id) {
        $model = new MemberDashboardLogic();
        $model->setToken($this->token);
        $model->workbook_id = $id;
        return $model->toArray();
    }

    /**
     * @inheritdoc
     */
    public function actionInvite() {
        $model = new BookMemberInviteForm();
        $model->user_id = $this->uid;
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('请完善信息后提交');
        }
        return $model->save();
    }

    /**
     * @inheritdoc
     */
    public function actionUpdate($id) {
        $model = new BookMemberForm($id);
        $model->user_id = $this->uid;
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('请完善信息后提交');
        }
        return $model->save();
    }

}
